import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {HttpServicesProvider} from "../../providers/http-services/http-services";
import {ValidateProvider} from "../../providers/validate/validate";

@IonicPage({
    segment: 'member/article/income/:amoy_id',
    defaultHistory: ['MemberPage', 'PersonMessagePage']
})
@Component({
    selector: 'page-income',
    templateUrl: 'income.html',
})
export class IncomePage {
    page:number = 1;
    lists = [];
    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public httpService: HttpServicesProvider,
        public validate: ValidateProvider
    ) {
    }
    ionViewCanEnter(){
        return this.validate.checkLogin();
    }

    ionViewDidLoad(){
        this.getData(null);
    }

    getData(infiniteScroll) {
        let postData = {
            amoy_id: this.navParams.get('amoy_id'),
            page: this.page
        };

        this.httpService.requestPostData('/user_info/my_income', postData, response => {
            if(response.error == 200){
                //全部数据
                let data = response['data'];
                this.lists = this.lists.concat(data['lists']);
                this.page++;
                if (infiniteScroll) {
                    infiniteScroll.complete();
                    /*请求完成数据更新页面*/
                    if (data['data'].length < 8) {   /*没有数据 禁用上拉更新*/
                        infiniteScroll.enable(false);
                    }
                }
            }else{
                if (infiniteScroll) {
                    infiniteScroll.enable(false);
                }
            }
        });
    }

    doInfinite(infiniteScroll) {
        this.getData(infiniteScroll);
    }

}
